package com.dk.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dk.pojo.Car;
import com.dk.pojo.Type;
import com.dk.service.carservice;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("car")
public class carcontroller {
    @Reference
    private carservice carservice;


    @RequestMapping("toShow")
    public String toShow(){
        return "car/show";
    }
    @RequestMapping("toUpdate/{id}")
    public String toUpdate(Model model, @PathVariable("id")Integer id){
        Car list = carservice.getnfoByCid(id);
        List<Type> t = carservice.getInfo();
        model.addAttribute("list",list);
        model.addAttribute("t",t);
        return "car/update";
    }
    @RequestMapping("toAdd")
    public String toAdd(Model model){
        List<Type> list = carservice.getInfo();
        model.addAttribute("list",list);
        return "car/add";
    }
    @RequestMapping("getInfo")
    @ResponseBody
    public List<Car> getInfo(){
        List<Car> list = carservice.getnfo();
        return list;
    }
    @RequestMapping("addInfo")
    @ResponseBody
    public boolean addInfo(Car car){
        boolean b = carservice.addInfo(car);
        return b;
    }

    @RequestMapping("deleteInfo/{cid}")
    @ResponseBody
    public boolean deleteInfo(@PathVariable("cid")Integer cid){
        boolean b = carservice.deleteInfo(cid);
        return b;
    }
    @RequestMapping("deleteAll")
    @ResponseBody
    public boolean deleteAll(@RequestParam("cid[]")Integer[] cid){
        boolean b = carservice.deleteAll(cid);
        return b;
    }
    @RequestMapping("updateInfo")
    @ResponseBody
    public boolean updatInfo(Car car){
        boolean b = carservice.updateInfo(car);
        return b;
    }
}
